package cn.yuanqiao.web.controller.cqbc;
/**
 * @author 赵常飞
 * @date 2024/6/14 15:47
 */

import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.cqbc.dataManage.domain.DataManage;
import cn.yuanqiao.cqbc.dataManageTreePath.domain.DataManageTreePath;
import cn.yuanqiao.cqbc.dataManageTreePath.service.IDataManageTreePathService;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 *@Author: 赵常飞
 *@Date: 2024/6/14 15:47
 *@Description:
 *@Note:
 */
@RestController
@RequestMapping("/cqbc/dataManageTreePath")
public class DataManageTreePathController extends BaseController {

    @Autowired
    private IDataManageTreePathService dataManageTreeService;

    @Log(title = "获取分类存储树", businessType = BusinessType.SELECT)
    @GetMapping("/gettrees")
    public AjaxResult gettrees(){
        return success(dataManageTreeService.getTreeList());
    }
    @Log(title = "给门类添加一个存储位置", businessType = BusinessType.INSERT)
    @PostMapping("/addPath")
    public AjaxResult addPath(@RequestBody DataManageTreePath dataManageTreePath){
        return success(dataManageTreeService.addPath(dataManageTreePath));
    }

    @Log(title = "获取门类的存储位置回显", businessType = BusinessType.SELECT)
    @PostMapping("/getPath/{categoryId}")
    public AjaxResult getPath(@PathVariable("categoryId") Long categoryId){
        return success(dataManageTreeService.getPath(categoryId));
    }

    @Log(title = "修改一个存储位置为启用", businessType = BusinessType.UPDATE)
    @PostMapping("/updateEnable")
    public AjaxResult updateEnable(@RequestBody DataManageTreePath dataManageTreePath){
        return success(dataManageTreeService.updateEnable(dataManageTreePath));
    }


    @Log(title = "删除一个存储位置", businessType = BusinessType.DELETE)
    @DeleteMapping("/deletePath/{pathId}")
    public AjaxResult deletePath(@PathVariable("pathId") Long pathId){
        return success(dataManageTreeService.deletePath(pathId));
    }

    @Log(title = "修改存储位置", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody DataManageTreePath dataManageTreePath){
        return success(dataManageTreeService.update(dataManageTreePath));
    }

    @Log(title = "获取列表数据", businessType = BusinessType.SELECT)
    @GetMapping("/getList")
    public TableDataInfo getList(@RequestBody JSONObject json){
        startPage();
        List<Map<String,Object>> list =dataManageTreeService.getList(json);
        return getDataTable(list);
    }

    @Log(title = "获取展示字段", businessType = BusinessType.SELECT)
    @GetMapping("/getshowFields")
    public AjaxResult getshowFields(@RequestBody JSONObject json){
        return success(dataManageTreeService.getshowFields(json));
    }

    @Log(title = "格式转换", businessType = BusinessType.OTHER)
    @PostMapping("/trans")
    public AjaxResult trans(@RequestBody JSONObject json) throws Exception {
        dataManageTreeService.trans(json);
        return success();
    }
    @Log(title = "获取查询字段", businessType = BusinessType.SELECT)
    @PostMapping("/getQueryFields")
    public AjaxResult getQueryFields(@RequestBody JSONObject json){
        return success(dataManageTreeService.getQueryFields(json));
    }
}
